package com.spzx.order.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.order.api.RemoteOrderInfoService;
import com.spzx.order.api.domain.OrderInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * ClassName: RemoteOrderInfoFallbackFactory
 * Package: com.spzx.order.api.factory
 * Description:
 *
 * @Author ycy
 * @Create 2024/9/2 17:21
 * @Version 1.0
 */
@Component
public class RemoteOrderInfoFallbackFactory implements FallbackFactory {

    private static final Logger log = LoggerFactory.getLogger(RemoteOrderInfoFallbackFactory.class);

    @Override
    public RemoteOrderInfoService create(Throwable cause) {

        log.error("订单服务调用失败:{}",cause.getMessage());

        return new RemoteOrderInfoService() {
            @Override
            public R<OrderInfo> getByOrderNo(String orderNo, String source) {
                return R.fail("根据订单号获取订单信息失败:" + cause.getMessage());
            }
        };
    }
}
